﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductTracking.aspx.cs" Inherits="UI_Bas_ProductTracking" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>商品管理——缺货跟踪</title>       
    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
 <script type ="text/javascript" >
    	$(function(){ 
    	 $("#ddlProcurementStatus").combobox({
            editable: false
        });
    	var defaultDate = Date.parse('1900/01/01');
        var _$productTracking = $("#productTracking");
        _$productTracking.datagrid({
            border: true,
            height: 345,
            width: 1100,
            title: '缺货列表...',            
            remoteSort: false,
            nowrap: true,   
            striped: false,
            url: "../../TableHanders.aspx?act=q&tid=45&type=0",
            sortName: 'ProductId',
            sortOrder: 'desc',
            loadMsg: "正在加载,请稍后...",
            frozenColumns: [[ 
                    { title: 'ck', field: 'CheckId', checkbox: true },
	                { title: '商品代码', field: 'ProductId', width:120, sortable: true},
	                { title: '日期',     field: 'DateTime',  width: 120, sortable: true, formatter: function(val) {
	                    var d = Date.parse(val.replace("-", "/"));
	                    if (d == defaultDate) {
	                        return "";
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                }
				  ]],
            columns: [[
                    { title: '规格型号', field: 'ProductSpecification', width:160, sortable: true},
                    { title: '商品名称', field: 'ProductName', width:400,sortable: true},
	                { title: '采购状态', field: 'ProcurementStatus', width:80, sortable: true,formatter: function(val) {
	                    if (val == 1) {
	                        return "未采购";
	                    }
	                    else if (val == 2) {
	                        return "已采购";
	                    }
	                    else if (val == 3) {
	                        return "不采购";
	                    }
	                    else {
	                        return val;
	                    }
	                 }
	                },
	                { title: '客服建议', field: 'Recommendations', width:130, sortable: true,formatter: function(val) {
	                    if (val == 0) {
	                        return "未处理";
	                    }
	                    else if (val == 1) {
	                        return "修改价格";
	                    }
	                    else if (val == 2) {
	                        return "商品下架";
	                    }
	                    else if (val == 3) {
	                        return "类似商品代替";
	                    }
	                     else if (val == 4) {
	                        return "盘亏单写入K3";
	                    }
	                    else {
	                        return val;
	                    }
	                 }
	                },
	                { title: '产品状态', field: 'IsOutOfStock', width:80,sortable: true,formatter: function(val){
	                    if (val ==4005) {
	                        return "在售";
	                    }
	                    else if (val ==4006) {
	                        return "临时停售";
	                    }
	                    else if (val == 4007) {
	                        return "淘汰";
	                    }
	                    else
	                    {
	                        return val ;
	                    }
	                  }
	                },		                
                    { title: '可用数量', field: 'LackNumber', width: 60, sortable: true },
                    { title: '可用天数', field: 'NumberOfDays', width:60, sortable: true}
				]],		   
            pagination: true,
            rownumbers: true,
            singleSelect: true,
            pageList: [10, 15, 20],
            queryParams: {
                    "timeFrom": $("#dateFrom").datebox('getValue'),
                    "timeTo": $("#dateTo").datebox('getValue'),
                    "productid":$("#txtProductId").val(),
                    "procurementStatus":$("#ddlProcurementStatus").combobox('getValue')                   
                },
            onSelect: function(index, data){                             
                 var rows = $('#productTracking').datagrid('getSelections');                 
                 if(data .Recommendations==2)
                 {
                    alert ("该商品已下架!..");
                    _$productTracking.datagrid("unselectRow",index);
                 }
               }
         });
         //查询
          $("#btnQuery").click(function() {
                if (!$("#divContent").form('validate'))
                   return;  
                var productid=$("#txtProductId").val();           
                var procurementStatus = $("#ddlProcurementStatus").combobox('getValue');
                var timeFrom = $("#dateFrom").datebox('getValue');
                var timeTo = $("#dateTo").datebox('getValue');
                _$productTracking.datagrid({
                    queryParams: {
                        "productid":productid,
                        "procurementStatus":procurementStatus,
                        "timeFrom": timeFrom,
                        "timeTo": timeTo
                    }
                });
            });
            $('#dateFrom').datebox({ formatter: function(date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
                }
            });
            $('#dateTo').datebox({ formatter: function(date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
                }
            });            
            //************************************修改价格******************************************  
            //修改价格
           $("#btnAlterPrice").click(function() {                            
                 var rows = $('#productTracking').datagrid('getSelections');
                 if(rows .length==0)
                 {
                    alert ('请选择一条商品记录！...');
                 }
                 else 
                 {
//                    var pids=[];                  
//                    for ( i=0;i<rows .length;i++)
//                     {
//                       pids.push(rows[i].ProductId);
//                     }
                     var pid=rows[0].ProductId;                      
                    var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=alterprice&pid=" + pid + "&ts=" + new Date().getTime();;
                    $.getJSON(url, function(data) {
                        var retData = EvalData(data);
                        var code = retData.retCode;
                        if (code == 0) {
                            alert ('价格修改成功！');
                            _$productTracking.datagrid("clearSelections");
                            _$productTracking .datagrid("reload");
                        }
                        else {
                            alert(retData.retMsg);
                        }
                   });
               }
            });
            //************************************商品下架******************************************  
            //下架
            $("#btnSaleStop").click(function() {                            
                 var rows = $('#productTracking').datagrid('getSelections');
                 if(rows .length==0)
                 {
                    alert ('请选择一条商品记录！...');
                 }
                 else 
                 {          
//                     var pids=[];
//                     for ( i=0;i<rows .length;i++)
//                     {
//                       pids.push(rows[i].ProductId);
//                     } 
                     var pid=rows[0].ProductId;  
                    var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=salestop&pid=" + pid + "&ts=" + new Date().getTime();;
                    $.getJSON(url, function(data) {
                        var retData = EvalData(data);
                        var code = retData.retCode;
                        if (code == 0) {
                            alert ('下架处理成功！');
                            _$productTracking.datagrid('clearSelections');
                            _$productTracking .datagrid("reload");
                        }
                        else {
                            alert(retData.retMsg);
                        }
                   });
               }
            });
            //************************************商品替换******************************************  
            //商品替换窗体
             $('#divpthuan').window({
                width: 500,
                height: 240,
                modal: true,
                shadow: false,
                closed: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                closable: false              
            });
            //商品替换
            $("#btnProductReplace").click(function (){
                var rows = $('#productTracking').datagrid('getSelections');
                 if(rows .length==0)
                 {
                    alert ('请选择一条商品记录！...');
                 }
                 else 
                 {                  
                     if(rows[0].ProcessingStatus==2)
                     {
                         alert ('该商品已下架！..');
                     } 
                     if(rows .length==1)
                     {                                  
                         var hid=rows[0].DeliveryWarehouseId ;
                         var pid=rows[0].ProductId;
                         $("#txthid").val(hid);
                         $("#txtProductA").val(pid); 
                         $('#divpthuan').window('open');
                     }  
                 }
            });
            //确定替换
             $("#btnthok").click(function() {
                var hid = $("#txthid").val();
                var opid = $("#txtProductA").val();
                var npid = $("#txtProductB").val();
                var oq = $("#txtOrginalQuantity").val();
                var nq = $("#txtNewQuantity").val();
                var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=spth&oq=" + oq + "&nq=" + nq + "&opid=" + opid + "&npid=" + npid +"&hid=" + hid +"&ts=" + new Date().getTime();
                $.getJSON(url, function(data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0){
                        alert("替换成功!!");
                        $("#txtProductA").val("");
                        $("#txtProductB").val("");
                        $('#divpthuan').window('close');
                        _$productTracking.datagrid('clearSelections');
                        _$productTracking .datagrid("reload");
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
              });
              //关闭弹出窗体
               $("#btnthclose").click(function() {
                $('#divpthuan').window('close');
            }); 
    
              
          //************************************修改可发数量(暂时不用)******************************************  
             //修改实际可发数量窗体
            $('#divxg').window({
                width: 400,
                height: 200,
                modal: true,
                shadow: false,
                closed: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                closable: false
            });                     
            // 修改可发数量
             $("#btnProductAlterNum").click(function (){
                var rows = $('#productTracking').datagrid('getSelections');
                 if(rows .length==0)
                 {
                    alert ('请选择一条记录！...');
                 }               
                 else 
                 {
                    
                     if(rows[0].ProcessingStatus==2)
                     {
                         alert ('该商品已下架！..');
                     }                              
                     var pid=rows[0].ProductId;                 
                     var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=getlisting&pid=" + pid + "&ts=" + new Date().getTime();
                     $.getJSON(url, function(data) {
                        var retData = EvalData(data);
                        var code = retData.retCode;
                        if (code == 0) {
                            $("#txtlisting").val(retData.xgnum);
                            $("#txtid").val(pid);
                            $('#divxg').window('open'); 
                        }
                        else {
                            alert(retData.retMsg);
                        }
                    });  
                }                            
            });
            //确定修改数量
            $("#btnxgok").click(function (){
                 var xgnum= $("#txtlisting").val();
                 var pid= $("#txtid").val();
                 var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=spxg&pid=" + pid +  "&xgnum=" + xgnum + "&ts=" + new Date().getTime();
                 $.getJSON(url, function(data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert("修改成功!!");
                        $("#txtlisting").val("");                       
                        $('#divxg').window('close');
                        _$productTracking.datagrid('clearSelections');
                        _$productTracking .datagrid("reload");
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });
             $("#btnxgclose").click(function() {
                $('#divxg').window('close');
            }); 
           //***************************************盘亏单写K3*************************************   
            $("#btnProductShortage").click(function (){
                var rows = $('#productTracking').datagrid('getSelections');
                 if(rows .length==0)
                 {
                    alert ('请选择一条记录！...');
                 }                
                 else 
                 {
                    
                     if(rows[0].ProcessingStatus==2)
                     {
                         alert ('该商品已下架！..');
                     }                              
                     var pid=rows[0].ProductId;
                     var stockid=rows[0].DeliveryWarehouseId;  
                     var qty=rows[0].LackNumber;
                     var url = getRootPath() + "/UI/Bas/ProductTrackingHandler.ashx?cmd=shortage&pid=" + pid +"&stockid=" + stockid +"&qty=" + qty +"&ts=" + new Date().getTime();
                     $.getJSON(url, function(data) {
                        var retData = EvalData(data);
                        var code = retData.retCode;
                        if (code == 0) {
                            alert("盘亏单写入成功!!");
                            _$productTracking.datagrid('clearSelections');
                            _$productTracking .datagrid("reload");
                        }
                        else {
                            alert(retData.retMsg);
                        }
                    });  
                }                            
            });
          //*******************************************************************************                                
        });
	</script>	
</head>
<body> 
       <form id="formQuery" runat="server" style ="width :1100px;">
          <div class="div_Title">
               <span class="Body_Title">》》<%=this.Title %></span>
          </div>  
          <div id="divContent" class="easyui-panel" title="请输入查询条件..." style="margin-bottom:5px;">
              <table >
                 <tr>
                    <td >商品代码:</td>
                    <td >
                        <input type="text" id="txtProductId" runat="server" class="easyui-validatebox"  style ="width :110px;"/>                        
                   </td>
                    <td >采购状态:</td>
                    <td >
                        <select id="ddlProcurementStatus" runat="server" class="easyui-validatebox" enableviewstate="false" style ="width :110px;"/>
                   </td>
                    <td>日期:</td>
                    <td>
                        <input type ="text" ID ="dateFrom" runat="server" class ="easyui-datebox" required="true" style ="width :120px;"  /></td>
                    <td> - </td>
                    <td>
                        <input type ="text" ID="dateTo"  runat="server" class ="easyui-datebox" required="true" style ="width :120px;" /></td>
                    <td> 
                        <a id="btnQuery"  href ="#"  class="easyui-linkbutton" icon="icon-search">Query</a></td>
                 </tr>
             </table> 
          </div>
          <div id ="divOperating"  class="easyui-panel" title="数据操作区..." style="margin-bottom:5px;">
             <table >
                   <tr>                   
                      <td align ="center" style ="width :130px;">                 
                          <a href ="#" id="btnAlterPrice" class="easyui-linkbutton" >修改价格</a>
                      </td>
                      <td align ="center" style ="width :130px;">
                          <a href ="#" id="btnSaleStop"   class="easyui-linkbutton" >商品下架</a>
                      </td>
                      <td align ="center" style ="width :150px;">                        
                          <a href ="#" id="btnProductReplace"  class="easyui-linkbutton" >类似商品替代</a>
                      </td>
                      <td align ="center" style ="width :200px;">
                         <%-- <a href ="#" id="btnProductAlterNum" class="easyui-linkbutton" >修改可发数量</a>--%>
                          <a href ="#" id="btnProductShortage" class="easyui-linkbutton" >盘亏单写入k3</a>
                      </td>
                  </tr>
              </table>
          </div>
          <table  id="productTracking"></table>
          
            <div id="divpthuan" title = "商品替换">
                <div style ="margin-top :20px; height :150px;">
                <input type="hidden" id="txthid" />
                  <table style="margin-left:110px"> 
                  <tr>
                      <td><p>原商品:</p></td>
                      <td>
                        <input type="text" id = "txtProductA" disabled =disabled  style="width:160px"/>
                      </td>
                   </tr>
                   <tr>
                      <td><p>替换商品:</p></td>
                      <td>
                        <input type="text" id="txtProductB" style="width:160px"/>
                      </td>                     
                   </tr>
                    <tr>
                      <td><p>替换比率:</p></td>
                       <td >
                        <input class="easyui-numberbox" type="text" id="txtOrginalQuantity" style="width:20px" value = "1" maxlength ="2"/>
                        <strong >:</strong>                       
                        <input class="easyui-numberbox" type="text" id="txtNewQuantity" style="width:20px" value="1" maxlength = "2"/>
                       </td>
                  </tr> 
                  </table>
                </div>
                <div style ="text-align:right ; margin-right :20px;" >
		            <a id="btnthok" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" >确定</a>
		            <a id="btnthclose" class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)">退出</a>
	            </div>
            </div>
            <div id="divxg" title = "修改商品实际可发数量">
                <div style ="margin-top :30px;">  
                    <input type="hidden" id="txtid" />
                  <table style="margin-left:60px"> 
                  <tr>
                      <td><p>近7天销售量最高Listing:</p></td>
                      <td>
                        <input type="text" id = "txtlisting" disabled =disabled  style="width:30px"/>
                      </td>                                           
                  </tr>
                  </table>
                </div>
                <div style=" text-align :right ; margin-top :50px; ">
		            <a id="btnxgok" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" >确定</a>
		            <a id="btnxgclose" class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)">退出</a>
	            </div>
            </div>                              
       </form>   
</body>
</html>
